<?php


namespace App\Services;


class BaseService
{
    protected static $instance;

    /**
     * @return static
     */
    public static function getInstance()
    {
        if(static::$instance instanceof static){
            return static::$instance;
        }
        static::$instance = new static();
        return static::$instance;
    }

    // 文件上传
    public function upfile($request,$url,$default,$file='users',$type='') {
        if($type=='img'){
            $allow_ext = ["png", "jpg", "jpeg", "gif"];// 允许上传的图片后缀
            $ext = $request->file('file')->getClientOriginalExtension();// 扩展名
            if (!in_array($ext, $allow_ext)) {
                return false;
            }
        }
        // 封面图片
        $pic = $default;
        if ($request->hasFile('file')) {
            // 上传
            // 参数2 配置的节点名称
            $ret = $request->file('file')->store(date('Ymd'), $file);
            $pic = $url . $ret;
        }
        return $pic;
    }

    private function __construct()
    {
    }
    private function __clone()
    {
    }
}
